package tech.dx.springdb.controller;

import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import tech.dx.springdb.entity.User;
import tech.dx.springdb.service.UserService;

import java.util.Optional;

/**
 * @ClassName UserController
 * @Description TODO
 * @Author daoxuan
 * @Date 2019/4/1 12:22
 * @Version 1.0
 */
@RestController
@RequestMapping("user")
@Api(tags = {"用户"})
public class UserController {

    @Autowired
    private UserService userService;

    @GetMapping(path = {"/{id}"})
    public User get(@PathVariable long id){
        Optional<User> byId = userService.getById(id);
        if (byId.isPresent()){
            return byId.get();
        }else {
            return null;
        }
    }
}
